

import _ from 'underscore'


var BaseView = R.View.extend({
  type: "BaseView",

  /*
   * override constructor to remember 'options'
   */
  constructor: function (options) {
    //remember options
    this.options = _.defaults(options, this.defaults) || {};
    R.View.apply(this, [this.options]);
    // default initElement after initialize
    this.initElement();
  },

  /*
   *  any render must do setOptions
   */
  setOptions:function () {

    this.setRender();
  },
  /*
   * override must call super for the right order
   */
  initElement: function () {
    //the configureElement is synchronous for the order
    this.configureElement();
    this.setRender();
  },
  //synchronous for the order
  setRender: function () {
    this.willRender();
    this.render();
    this.didRender();
  },
  //Normal should call only once
  configureElement: function () {},

  //override for deciding how to do render
  willRender: function () {

  },
  //render can get the final dom
  render: function () {

  },

  didRender: function () {},

  willUnmount: function () {},

  // override for the didMount  lifycycle support
  removeElement: function () {
    this.willUnmount();
    R.View.prototype.removeElement.apply(this, arguments);
  }

})



export default BaseView
